/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package plp1;
/**
 *
 * @author eltorre
 */


public class MyToken{

	private int fila;
	private int columna;

	static public int	PARI	=	1,
						PARD	=	2,
						PYC		=	3,
						ASIG	=	4,
						CLASS	=	5,
						DOUBLE	=	6,
						INT		=	7,
						MAIN	=	8,
						VOID	=	9,
						LLAVEI	=	10,
						LLAVED	=	11,
						ENTERO	=	12,
						ID		=	13,
						REAL	=	14,
						COMENTARIO = 15,
						EOF = 16,
						ERROR = 0;

	static public String Tipos[] = {	"ERROR",
										"(",
										")",
										";",
										" ",
										"class",
										"double",
										"int",
										"main",
										"void",
										"{",
										"}",
										"entero",
										"id",
										"real",
										"comentario",
										"$"};

	static public String Salida[] = {	"ERROR",
										" (",
										")",
										";\n",
										" = ",
										"class ",
										"double ",
										"int ",
										"main",
										"void ",
										" {\n",
										"}\n",
										"entero",
										"identificador",
										"real",
										"comentario",
										"$"};

		static public String SalidaError[] = {	"ERROR",
											"'('",
											"')'",
											"';'",
											"'='",
											"'class'",
											"'double'",
											"'int'",
											"'main'",
											"'void'",
											"'{'",
											"'}'",
											"entero",
											"identificador",
											"real",
											"comentario",
											"final de fichero"};

	private String cadena;	//Cadena que se muestra
	private int tipo;		//Tipo del token.


	public MyToken (int t)
	{
		tipo = t;
		cadena = Salida[t];
	}

	public MyToken (int t, int f, int c)
	{
		tipo = t;
		fila = f;
		columna = c;
		cadena = Salida[t];
	}

	public MyToken (String p, int t, int f, int c)
	{
		cadena = p;
		tipo = t;
		fila = f;
		columna = c;
	}

	public MyToken (MyToken t)
	{
		cadena = t.cadena;
		tipo = t.tipo;
		fila = t.fila;
		columna = t.columna;
	}

	public String getError()
	{
		if (tipo <= 12)
		{
			return SalidaError[tipo];
		}
		else
		{
			if (cadena.equals(Salida[tipo]))
				return SalidaError[tipo];
			return "'" + cadena + "'";
		}

	}

	@Override
	public String toString()
	{
		String ret = "Token : Fila: " + fila + " Columna: " + columna + " \tTipo = " + Salida[tipo] + "\tCadena = " + cadena;


		return ret;
	}

	public int getFila()
	{
		return fila;
	}

	public int getColumna()
	{
		return columna;
	}

	public String getTipo()
	{
		if (tipo <= 12)
		{
			return Tipos[tipo];
		}
		else
			return cadena;
	}

	public String getLexema()
	{
		return cadena;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final MyToken other = (MyToken) obj;
		if (this.tipo != other.tipo) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		int hash = 7;
		hash = 47 * hash + this.tipo;
		return hash;
	}

	public boolean isEof()
	{
		return tipo == EOF;
	}



}